import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { PPPListTree } from '../Common/Conversion'

export const PPPList = async ({ url, OptionsEvent, Permission }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}Tree`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === 'd8e63cad-c0bd-46c2-9eab-899a32df658d') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, rules: true, width: 400 },
            { ...commonTableList.code, rules: true },
            {
                ...commonTableList.parentUuid,
                fieldProps: {
                    fieldNames: { label: 'tableName', value: 'uuid' },
                    options: await PPPListTree(),
                },
                width: 400,
            },

            { ...commonTableList.sortId, rules: true },
            {
                dataIndex: 'isImportant',
                title: '重要节点',
                valueType: 'select',
                valueEnum: BuiltInData.isYes,
                rules: true,
                width: 150,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { children } = record
                    return [
                        Permission.findIndex(v => v.uuid === '0a3c1767-d509-4e32-a5fd-35b7f8e6d904') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === '11c84c81-5fb4-4528-a1f9-f1fa292a01e7') !== -1 &&
                            !children && (
                                <DelDataButton
                                    OptionsEvent={OptionsEvent}
                                    key="del"
                                    title="删除"
                                    url={url}
                                    uuid={record.uuid}
                                />
                            ),
                    ]
                },
            },
        ],
    }
    return data
}
